import { defHttp } from '@/utils/http/axios';
import { RequestEnum } from '@/enums/httpEnum';
import type { AxiosRequestConfig } from 'axios';
import { ServicePrefixEnum } from '@/enums/commonEnum';

const MODULAR = 'file';

export const Api = {
    upload: {
        url: `${ServicePrefixEnum.BASE}/${MODULAR}/upload`,
        method: RequestEnum.POST,
    } as AxiosRequestConfig,
    getDownloadUrl: {
        url: `${ServicePrefixEnum.BASE}/${MODULAR}/get_download_url`,
        method: RequestEnum.GET,
    } as AxiosRequestConfig,
    download: {
        url: `${ServicePrefixEnum.BASE}/${MODULAR}/download`,
        method: RequestEnum.GET,
    } as AxiosRequestConfig,
}

/**
 * params是{file:{}}
 * @param params
 */
export const upload = (params) => {

   return  defHttp.uploadFile({...Api.upload},params)
}

/**
 * params是{fileKey:''}
 * @param params
 */
export const getDownloadUrl = (params) => {
    return  defHttp.request({ ...Api.getDownloadUrl
        , params })
}

/**
 * params是{fileKey:''}
 * @param params
 */
export const download = (params) => {
    return  defHttp.request({ ...Api.download
        , params })
}


